<?php

namespace App\Clients\JinShouFu;

use GuzzleHttp\Exception\GuzzleException;
use phpQuery;

class ExportRecordPage extends JinShouFuClient
{
    protected $isJson = false;

    public function handleData(): void
    {
        $html = phpQuery::newDocument($this->contents);
        $dataList = [];
        $html->find(".table tr:gt(0)")->each(function($item)use(&$dataList){
            $ele = pq($item);
            $first = trim($ele->find("td:eq(0)")->text());
            if($first == "暂无数据！") return;
            $data = [
                "merchantName"=>trim($ele->find("td:eq(0)")->text()),
                "fileName"=>trim($ele->find("td:eq(1)")->text()),
                "createdAt"=>trim($ele->find("td:eq(2)")->text()),
                "fileUrl"=>$ele->find("td:eq(-1) a:eq(0)")->attr("href"),
            ];
            $dataList[] = $data;
        });
        $this->contents = $dataList;
    }


    /**
     * @throws GuzzleException
     */
    public function execute($queryData): ExportRecordPage
    {
        return $this->get("https://www.jsfpay.com/exportRecord/page.do",$queryData);
    }
}
